package com.jeesite.modules.dp.web;

import com.aliyuncs.utils.StringUtils;
import com.jeesite.modules.dp.entity.vipinfo.DpVipinfo;
import com.jeesite.modules.dp.service.vipinfo.DpVipinfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping(value = "f/main")
public class FrontMainController {

    @Autowired
    private DpVipinfoService dpVipinfoService;

    @RequestMapping(value = "viplist")
    @ResponseBody
    public Map<String, Object> viplist() {
        Map<String, Object> rs = new HashMap<String, Object>();
        List<DpVipinfo> list = dpVipinfoService.findList(new DpVipinfo());

        int max = 0;
        for (DpVipinfo info : list) {
            String qyString = info.getVipcontent();
            List<String> qylist = new ArrayList<String>();
            if (StringUtils.isEmpty(qyString)) {
                info.setQylist(qylist);
            } else {
                String[] tmp = qyString.split("\n");
                info.setQylist(Arrays.asList(tmp));

                if (max < tmp.length) {
                    max = tmp.length;
                }
            }

        }
        rs.put("list", list);
        rs.put("maxrow", max + 1);
        return rs;
    }

    @RequestMapping("stop")
    @ResponseBody
    public String stop(){
        System.exit(-1);
        return "success";
    }
}
